package com.pt.pok.protobuf;

import com.pt.pok.*;
import com.pt.pok.model.ClassIds;

/**
 * @author Andrey.Panfilov@playtech.com
 */
public class ProtobufConverterFactory
    implements ConverterFactory<byte[]> {

    public ProtocolConverter<byte[]> getProtocolConverter() {
        Dispatcher<byte[]> dispatcher = new ProtobufDispatcher();

        initializeHandlers(dispatcher);
        initializeMarshallers(dispatcher);

        return new ProtobufProtocolConverter(dispatcher);
    }

    private void initializeMarshallers(Dispatcher<byte[]> dispatcher) {
        ProtocolMarshaller<byte[]> loginCommandMarshaller = new LoginCommandMarshaller();

        dispatcher.registerMarshaller(ClassIds.LOGIN_REQUEST.getId(), loginCommandMarshaller);
    }

    private void initializeHandlers(Dispatcher<byte[]> dispatcher) {
        CommandHandler<byte[]> loginRequestCommandHandler = new LoginRequestCommandHandler();

        dispatcher.registerHandler(ClassIds.LOGIN_REQUEST.getId(), loginRequestCommandHandler);
    }

}
